//
//  HomeTitleButton.swift
//  HMWeibo007
//
//  Created by TTang on 15/7/4.
//  Copyright © 2015年 shanyu. All rights reserved.
//

import UIKit

class HomeTitleButton: UIButton {

    
    class func button(title: String) -> HomeTitleButton {
        
        let btn = HomeTitleButton()
        
        btn.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(17)
        btn.setTitle(title + " " , forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "navigationbar_arrow_down"), forState: UIControlState.Normal)
        btn.sizeToFit()
        return btn
    }
    
    ///  自定义标题按钮，调整文本和图像的位置
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
//        var tFrame = titleLabel!.frame
//        tFrame.origin.x = 0
//        titleLabel?.frame = tFrame
//        var iFrame = imageView!.frame
//        iFrame.origin.x = tFrame.width
//        imageView?.frame = iFrame

        /// swift2.0中，可以直接修改frame内部的值
        titleLabel!.frame.origin.x = 0
        imageView!.frame.origin.x = titleLabel!.bounds.width
    }

}
